﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Ajax_Default : PageBase
{
    static string ErrorFormat = "{{'bOk':false,'sMsg':'{0}','mDebug':'{1}'}}";

    private void Write(string str)
    {
        Response.ClearContent();
        Response.Write(str);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        var typestring = Request["type"] != null ? Request["type"].ToLower() : "";
        var actionstring = Request["action"] != null ? Request["action"].ToLower() : "";
        var output = new StringBuilder();
        if (string.IsNullOrWhiteSpace(typestring))
        {
#if Debug
            output.AppendLine(string.Format(ErrorFormat,"No this action","Type Missing"));
#else
            output.AppendLine(string.Format(ErrorFormat, "No this action", " "));
#endif
            Write(output.ToString());
            return;
        }

        if (string.IsNullOrWhiteSpace(actionstring))
        {
#if Debug
            output.AppendLine(string.Format(ErrorFormat,"No this action","Type Missing"));
#else
            output.AppendLine(string.Format(ErrorFormat, "No this action", "").Replace("'", "\""));
#endif
            Write(output.ToString());
            return;
        }

        switch (typestring)
        {
            case "signin":
                switch (actionstring)
                {
                    case "signin":
                        Write(SignIn.DoSignIn(Request, Session));
                        break;
                    case "signup":
                        Write(SignIn.DoSignUp(Request, Session));
                        break;
                }
                break;
            case "singleplay":
                switch (actionstring)
                {
                    case "getmap":
                        Write(SinglePlay.GetMap(Request,Session));
                        break;
                }
                break;
        }
    }
}